package cn.tannn.ip2region.server.api;

import cn.tannn.ip2region.api.IpApi;
import cn.tannn.ip2region.sdk.IpRegionUtil;
import cn.tannn.ip2region.sdk.IpUtil;
import cn.tannn.jdevelops.result.response.ResultVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * ip
 *
 * @author <a href="https://tannn.cn/">tan</a>
 * @date 2023/9/13 10:09
 */
@Tag(name = "IP查询", description = "IP查询")
@RestController
@RequestMapping("ip")
public class IpController implements IpApi {

    @Override
    public ResultVO<String> findRegionAt(HttpServletRequest request) {
        return ResultVO.success(IpRegionUtil.getIpRegion(request));
    }

    @Override
    public ResultVO<String> findRegion(@RequestParam("ip") String ip) {
        return ResultVO.success(IpRegionUtil.getIpRegion(ip));
    }

    @Override
    public ResultVO<String> findRegionFromPconline(@RequestParam("ip") String ip) {
        return ResultVO.success(IpUtil.getIpRegionOnline(ip));
    }
}
